package org.liaohailong.victorlibrary.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.liaohailong.victorlibrary.R;

/**
 * Author: Victor
 * Date: 2019/5/17 9:35
 * Description: 头部滑动界面
 */
public class HeaderScrollActivity extends Activity {
    public static void show(Context context) {
        Intent intent = new Intent(context, HeaderScrollActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_header_scroll);
        RecyclerView recyclerView = findViewById(R.id.content_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new Adapter());
    }

    private final class Adapter extends RecyclerView.Adapter<ViewHolder> {

        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_textview, parent, false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            if (holder.itemView instanceof TextView) {
                TextView textView = (TextView) holder.itemView;
                textView.setText(String.valueOf(position));
            }
        }

        @Override
        public int getItemCount() {
            return 60;
        }
    }

    private final class ViewHolder extends RecyclerView.ViewHolder {

        private ViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
